﻿using System;
using System.Windows;
using Dsl.Ped.Common.Converters;
using NUnit.Framework;

namespace DSLPedCommonTest.Converters
{
    [TestFixture]
    public class CombiningConverterTest
    {
        private CombiningConverter negatedBoolToVisibilityConverter;

        [SetUp]
        public void SetUpForEachTest()
        {
            negatedBoolToVisibilityConverter = new CombiningConverter()
            {
                Converter1 = new NegatedBoolConverter(),
                Converter2 = new BoolToVisibilityConverter()
            };
        }

        [Test, Description("First convert true/false into its negative (false/true), convert false to visibility (hidden/visible)")]
        public void NegatedBool2VisibilityWithoutParameterTest()
        {
            var visibility = negatedBoolToVisibilityConverter.Convert(true, typeof(bool), null, null);

            Assert.AreEqual(Visibility.Hidden, (Visibility)visibility);

            visibility = negatedBoolToVisibilityConverter.Convert(false, typeof(bool), null, null);

            Assert.AreEqual(Visibility.Visible, (Visibility)visibility);
        }

        [Test, Description("First convert true/false into its negative (false/true), convert false to visibility (collapsed/visible), collapsed is in parameter")]
        public void NegatedBool2VisibilityWithParameterTest()
        {
            var visibility = negatedBoolToVisibilityConverter.Convert(true, typeof(bool), "Collapsed", null);

            Assert.AreEqual(Visibility.Collapsed, (Visibility)visibility);

            visibility = negatedBoolToVisibilityConverter.Convert(false, typeof(bool), null, null);

            Assert.AreEqual(Visibility.Visible, (Visibility)visibility);
        }

        [Test, Description("Any back-conversion, check, NotImplementedException has been thrown")]
        public void CombiningConvertBackTest()
        {
            try
            {
                var obj = negatedBoolToVisibilityConverter.ConvertBack(true, typeof(bool), null, null);
            }
            catch (NotImplementedException)
            { /* OK, we expect NotImplemented exception*/ }
        }
    }
}
